﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _2_6
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // 默认设置为1890年到今年
            txtStartYear.Text = "1890";
            txtEndYear.Text = DateTime.Now.Year.ToString();
        }

        private bool IsLeapYear(int year)
        {
            return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            try
            {
                int startYear = int.Parse(txtStartYear.Text);
                int endYear = int.Parse(txtEndYear.Text);

                if (startYear > endYear)
                {
                    MessageBox.Show("起始年份不能大于结束年份！");
                    return;
                }

                txtResult.Text = "";
                int count = 0;

                for (int year = startYear; year <= endYear; year++)
                {
                    if (IsLeapYear(year))
                    {
                        txtResult.Text += year.ToString().PadRight(6);
                        count++;

                        if (count % 5 == 0) // 每5个换一行
                            txtResult.Text += Environment.NewLine;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("请输入有效的年份！");
            }
        }
    }

}
